<?php
include_once('../lib/Sqlexecutor.php');
include_once('../lib/Login.php');
include('log4php/Logger.php');

$dbh = new Sqlexecutor('localhost', 'tile', 'tile', 'tile');
Logger::configure('config.ini');
$logger = Logger::getLogger('intf');

$s = new Login($dbh, $logger);

$usrid = isset($_REQUEST['usrid']) ? $_REQUEST['usrid'] : 0;
$sessionid = isset($_REQUEST['sessionid']) ? $_REQUEST['sessionid'] : '';

if($usrid == 0 || $sessionid == '')
{
    $res['errno'] = -2; 
    $output = json_encode($res); 
    $logger->trace("input: usrid=$usrid, sessionid=$sessionid; res: $output"); 
    echo $output;
    exit;
}

$info = $s->isLogin($usrid, $sessionid);
if($info === "0" or $info === "1")
{
    $rst = $s->getInfoByID($usrid);
    $res['info'] = $rst;
    $res['errno'] = 0;
}
else
{
    $res['errno'] = $info;
}

$output = json_encode($res); 
$logger->trace("input: usrid=$usrid, sessionid=$sessionid; res: $output"); 
echo $output;
?>
